﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ISRecord.Model.Properties;

namespace ISRecord.Model
{
    internal static class Helper
    {
        internal static int StartNewIncrement(string activeYear)
        {
            string s = activeYear + "0001";
            return int.Parse(s);
        }


        internal static string ApplayOutboxNoPattern(string outboxNo, string currentYear)
        {
            switch (outboxNo.Length)
            {
                case 1:
                    return string.Format("{0}{1}{2}", currentYear, "000", outboxNo);
                case 2:
                    return string.Format("{0}{1}{2}", currentYear, "00", outboxNo);
                case 3:
                    return string.Format("{0}{1}{2}", currentYear, "0", outboxNo);
                case 4:
                    return string.Format("{0}{1}", currentYear, outboxNo);
                default:
                    return outboxNo;
            }    
        }


        internal static bool IsValidDate(string dateString)
        {
            bool result = false;
            if (string.IsNullOrEmpty(dateString)) { return false; }
            if (dateString.Length != 8) { return false; }
            string d = dateString.Substring(6, 2);
            string m = dateString.Substring(4, 2);
            string y = dateString.Substring(0, 4);
            
            int day;
            int month;
            int year;

            if (int.TryParse(d, out day) &&
                int.TryParse(m, out month) &&
                int.TryParse(y, out year))
            {
                if (
                     (day > 0 && day < 31)
                     &&
                     (month > 0 && month <= 12)
                     &&
                     (year > 1400))
                {
                    result = true;
                }
            }
            return result;
        }
    }
}
